using System;
using System.Data;
using System.Data.OleDb;
using System.Configuration;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.Collections;
using System.Collections.Specialized;

namespace ExcelSample {
    public class Populate : Page {
        DataAccess da = new DataAccess ();            

        public Populate (string StrDatabase) {
            switch (StrDatabase) {
                case "new":
                    da.SubConnect ();
                    break;
                case "old":
                    da.MainConnect ();
                    break;
                default:
                    da.MainConnect ();
                    break;
            }
        }

        public void QueryRange (ref GridView gvGrid, string strParse, string range) {
            StrSelected = strParse;
            OleDbConnection objConn = new OleDbConnection (da.StrConnectionString);
            try {
                objConn.Open ();
                OleDbCommand objCmdSelect = new OleDbCommand ("SELECT " + StrSelected + " FROM " + range, objConn);
                OleDbDataAdapter objAdapter1 = new OleDbDataAdapter ();
                objAdapter1.SelectCommand = objCmdSelect;
                DataSet objDataset1 = new DataSet ();
                objAdapter1.Fill (objDataset1, "XLData");
                gvGrid.DataSource = objDataset1.Tables[0].DefaultView;
                gvGrid.DataBind ();
            } catch (OleDbException exc) {
                
            } finally {
                objConn.Close ();
            }
        }

        private string strSelected;
        protected string StrSelected {
            get { return strSelected; }
            set { strSelected = value; }
        }

        private string strDatabase;
        protected string StrDatabase {
            get { return strDatabase; }
            set { strDatabase = value; }
        }
    }
}